<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
  <script src="https://unpkg.com/mitt/dist/mitt.umd.js"></script>
  <script>
    const CommonChild = {
      template: `
        <div>
          这是子组件1
          {{ a }}
          {{ d }}
        </div>
      `,
      // 子组件通过inject属性 注入 父组件提供数据  依赖注入
      inject: ['a', 'd']
    }
    const CommonChild2 = {
      template: `
        <div>
          这是子组件2
          {{ b }}
          {{ c }}
        </div>
      `,
      inject: ['b', 'c']
    }
    const CommonHead = {
      // 模板视图
      template: `
        <div>
          这是父组件
          <hr/>
          <common-child></common-child>
          <hr/>
          <common-child2></common-child2>
        </div>
      `,
      // 通过provide 提供数据
      provide: {
        a: 10,
        b: '这是b',
        c: 20,
        d: [1,2,3,4]
      },
      components: {
        CommonChild,
        CommonChild2
      }
    }
    Vue.component('CommonHead', CommonHead);
    const vm = new Vue();
    vm.$mount('#app')
  </script>
</body>

</html>